<?php
	session_start();
	include "include.php";
?>
<html>
<head>
<title><?php echo $SITE_TITLE ?> - Import a Raid</title>
<link rel="stylesheet" type="text/css" href="main.css" /></head>
<div id="container">
<div id="top">
<h1><?php echo $SITE_TITLE ?></h1>
</div>
<div id="leftnav">
<?php include "leftnav.php" ?>
</div>
<div id="content">
<?php
	mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die(mysql_error());
	mysql_select_db(DB_NAME);
	
	$input_data = $_POST["input_xml"];
	$xmlparser = xml_parser_create();
	$xmldata = $input_data;
	$xmldata = str_replace("\\\"","\"",$xmldata);
	$xmldata = str_replace("\\\\","\\",$xmldata);
	$xmldata = str_replace("\\r","",$xmldata);
	$xmldata = str_replace("\\n","",$xmldata);
	if(!xml_parse_into_struct($xmlparser,$xmldata,$values)) {
		echo "Error in inporting loot, please PM the data to Lilcure for verification.<br>";
	}
	else {
		echo "<FORM action=\"import_confirm.php\" method=\"post\">\n<p>\n";
		xml_parser_free($xmlparser);
		for($x=0;$x<sizeof($values);$x++) {
			if($values[$x]['tag'] == "LOOT") {
				if($values[$x]['type'] == "cdata") { 	
					$x = $x + 3;														
					$loot_items_id = $values[$x]['value'];
					$x = $x + 6;														
					$loot_players_name = $values[$x]['value'];
					$x = $x + 6;	
// 2008-12-16T02:15:53Z
				}
				else if($values[$x]['type'] == "open") {
					$x = $x + 2;														
					$loot_items_id = $values[$x]['value'];
					$x = $x + 6;														
					$loot_players_name = $values[$x]['value'];
					$x = $x + 6;	
				}
				$date_loot = explode("T",$values[$x]['value']);
				$date_portion = $date_loot[0];
				$time_portion = str_replace("Z","",$date_loot[1]);
				$date_array = explode("-",$date_portion);
				$time_array = explode(":",$time_portion);
				$loot_date = gmmktime($time_array[0],$time_array[1],$time_array[2],$date_array[1],$date_array[2],$date_array[0]);
				if($loot_date && $loot_players_name && $loot_items_id) {
					add_loot($loot_date,$loot_players_name,$loot_items_id);
					echo "Importing loot for " . $loot_players_name . " | " . get_item_name($loot_items_id) . " | <input type=\"checkbox\" name=\"rot_" . get_last_loot_index() . "\" value=\"Rot\"> Rot.<br>";
				}
			}
		}
		echo "Data successfully imported.<br>";
		echo "    <INPUT type=\"submit\" value=\"Send\"> <INPUT type=\"reset\">\n</P>\n</FORM>\n";

	}

?>
</div>
<div id="footer">
<?php include "footer.php" ?>
</div>
</div>
</body>
</html>